﻿XIncludeFile "Function.pb"

;==============================函数类型===============================

;==================================常数==================================
Enumeration
 #Style=1
 #Visible=2
 #Enabled=4
EndEnumeration

;==============================窗口结构==============================
Structure GdipAnima Extends PWnd
  Style.B
  Sleep.l
  MouseStrar.l
EndStructure



;================================函数===========================================
Global GdipAnimation.l



Procedure DrawButtonStare(*Anima.GdipAnima)
  GdipDisposeImage(*Anima\Creat\ImageBack) 
  GdipCreateBitmapFromScan0(*Anima\Width,*Anima\Height,0,#GDIPLUS_PIXELFORMAT_32bppARGB, 0,@*Anima\Creat\ImageBack)
  GdipGetImageGraphicsContext(*Anima\Creat\ImageBack,@Graphics)
  GdipDrawImageRectRectI(Graphics, *Anima\Image, 0, 0,*Anima\Width,*Anima\Height, *Anima\Width * *Anima\Enabled, 0, *Anima\Width,*Anima\Height, #UnitPixel,#Null, #Null, #Null)
  GdipDeleteGraphics(Graphics)
EndProcedure

Procedure IButText(*Anima.GdipAnima,Text.s)
 
EndProcedure

Procedure IButSize(*Anima.GdipAnima,Width,Height)
  *Anima\Width =Width
  *Anima\Height=Height
  With *Anima\Creat
    GdipDisposeImage(\ImageBack)
    \ImageBack=GdipCreateImage(Width,Height)
  EndWith
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Procedure IButLoad(*Anima.GdipAnima)
  DrawButtonStare(*Anima.GdipAnima)
EndProcedure

Procedure IButDraw(*Anima.GdipAnima,*Gadget.PWnd,*cRect.RECT)

EndProcedure

Procedure IButEvent(*Anima.GdipAnima,hWnd, uMsg, wParam, lParam)
  If *Anima\Enabled =3
    ProcedureReturn  1
  EndIf 
  
  ProcedureReturn  1
EndProcedure

Procedure IButIsLoca(*Anima.GdipAnima,hWnd,X,Y)
  X-*Anima\X
  Y-*Anima\Y
  If X>-1 And Y>-1 And X<*Anima\Width And Y<*Anima\Height  And *Anima\Visible
     GdipBitmapGetPixel(*Anima\Creat\ImageBack,X,Y,@Color)
     If GdipAlpha(Color)
        ProcedureReturn *Anima
     EndIf 
  EndIf 
EndProcedure

Procedure IButFree(*Anima.GdipAnima)
  GdipDisposeImage(*Anima\Image)  ;当前绘制的图片
  GdipDisposeImage(*Anima\Draw)
  GdipDisposeImage(*Anima\Creat\ImageBack)   ;绘制缓冲
  
  DeleteWindowList(*Anima)
EndProcedure

Procedure GdipCreateButton(*Hwnd.PWnd,Image,X,Y,Width,Height,Text.s="",Style=6,ModeSource=#CompositingModeSourceOver)
 *Anima.GdipAnima=AddWindowList(@*Hwnd\Gadget,SizeOf(GdipAnima))

 GdipCloneImage(Image,@*Anima\Image)
 GdipCloneImage(Image,@*Anima\Creat\ImageBack)
 *Anima\Creat\ImageBack=GdipCreateImage(Width,Height)

 With *Anima
    \X=X
    \Y=Y
    \Width=Width
    \Height=Height
    \ModeSource=ModeSource
    \Visible=IsVal(Style,#Visible)
    \Enabled=(1-IsVal(Style,#Enabled))*3
    \Type=#Button
    \Style=IsVal(Style,1)
    \HostGadget=*Hwnd
    *Hwnd\NewGadget=*Anima
    \wIsLoca=@IButIsLoca()
    \wLoad=@IButLoad()
    \wDraw=@IButDraw()
    \wEvent=@IButEvent()
    \wFree=@IButFree()
    \wSize=@IButSize()
    \wText=@IButText()   
  EndWith
  ProcedureReturn *Anima
EndProcedure
; IDE Options = PureBasic 4.30 (Windows - x86)
; CursorPosition = 18
; Folding = --
; EnableAsm
; EnableUnicode
; EnableXP